package com.example.springboot.service;


import com.example.springboot.domain.Girl;
import com.example.springboot.enums.ResultEnum;
import com.example.springboot.exception.GirlException;
import com.example.springboot.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;
    /**
     * 简单的在代码里组装报文，不用前台传
     */
    @Transactional
    public void insertTwo(){
        Girl girlA =  new Girl();
        girlA.setAge(29);
        girlA.setCupSize("C");
        girlRepository.save(girlA);
        Girl girlB =  new Girl();
        girlB.setAge(30);
        girlB.setCupSize("C");
        girlRepository.save(girlB);
    }

    public void getAge(Integer id) throws Exception {
        Girl girl = girlRepository.findOne(id);
        Integer age = girl.getAge();
        if(age<10){
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        }if(age>10 && age< 18) {
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }
    }


}
